package beans;

import sqlInject.Payload;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by td on 2017/7/3.
 */
public class TimeDelayPayload {
    private String delayPayload;
    private  static  final long TIME= 5L;
    private static List<TimeDelayPayload> timeDelayPayloadList = null;
    private static BufferedReader bufferedReader = new BufferedReader(new InputStreamReader( Payload.class.getClassLoader().
            getResourceAsStream("sqlerrors.txt")));

    public static List<TimeDelayPayload> getTimeDelayPayloadInstance(){
        if (timeDelayPayloadList == null){
         timeDelayPayloadList = new ArrayList<TimeDelayPayload>();
         String line = "";
            try {
                while ((line=bufferedReader.readLine())!=null&&!line.trim().equals("")){
                    TimeDelayPayload timeDelayPayload = new TimeDelayPayload(line);
                    timeDelayPayloadList.add(timeDelayPayload);
                }
                bufferedReader.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return timeDelayPayloadList;
        }
        return timeDelayPayloadList;
    }

    public TimeDelayPayload(String delayPayload) {
        this.delayPayload = delayPayload;
    }

    public TimeDelayPayload(String delayPayload,long TIME){
         delayPayload = delayPayload.replaceAll("time",TIME+"");
        this.delayPayload = delayPayload;
    }


    public String getDelayPayload() {
        return delayPayload;
    }

    public void setDelayPayload(String delayPayload) {
        this.delayPayload = delayPayload;
    }

    public static long getTIME() {
        return TIME;
    }
}
